<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;


class LoginController extends Controller
{

    //登录页
    public function index()
    {
        return view('admin.login.index');
    }

    //登录行为
    public function login()
    {
        $this->validate(request(), [
            'name' => 'required|min:2',
            'password' => 'required|min:5|max:10|alpha_dash',
        ]);

        $user = request(['name', 'password']);

        if (\Auth::guard('admin')->attempt($user)) {
            return redirect('/admin/home');
        }
        return \Redirect::back()->withErrors("用户密码不匹配");
    }

    //登出行为
    public function logout()
    {
        \Auth::guard('admin')->logout();
        return redirect('/admin/login');
    }
}
